package _04_priorityQueue;

import _02_sortedSinglyLinkedList.SortedSinglyLinkedList;
import _04_seqQueue.Queue;

public final class PriorityQueue<T extends Comparable<? super T>> implements Queue<T> {
    
    private SortedSinglyLinkedList<T> list;
    
    // 构建空队列，asc指定升序(true)或降序(false)
    public PriorityQueue(boolean asc) {
        this.list = new SortedSinglyLinkedList<T>();
    }
    
    // 默认升序
    public PriorityQueue() {
        this(true);
    }
    
    // 根据数组构建优先队列
    public PriorityQueue(T[] objs, boolean asc) {
        this(asc);
        for (int i = 0; i < objs.length; i++) {
            this.add(objs[i]);
        }
    }

    // 判空
    public boolean isEmpty() {
        // TODO Auto-generated method stub
        return this.list.isEmpty();
    }

    // 插入x元素
    public boolean add(T x) {
        // TODO Auto-generated method stub
        return this.list.insert(x) != null;
    }


    // 返回队头元素
    public T peek() {
        // TODO Auto-generated method stub
        return this.list.get(0);
    }

    // 出队
    public T poll() {
        // TODO Auto-generated method stub
        return this.list.remove(0);
    }
    
    public String toString() {
        return this.list.toString();
    }
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

}
